package cn.peng.stu4teach.pages.my;

import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;

import androidx.databinding.library.baseAdapters.BR;
import androidx.lifecycle.ViewModelProvider;

import cn.peng.stu4teach.R;
import cn.peng.stu4teach.databinding.FmMyBinding;
import cn.peng.stu4teach.util.base.BaseFragment;
import cn.peng.stu4teach.util.update.ApkDownloadReceiver;

/**
 * 我的
 * A simple {@link BaseFragment} subclass.
 * Use the {@link MyFragment#newInstance} factory method to create an instance of this fragment.
 */
public class MyFragment extends BaseFragment<FmMyBinding, MyFmVm> {
    private       BroadcastReceiver mReceiver;

    private MyFragment () {
    }

    public static MyFragment newInstance () {
        return new MyFragment();
    }

    @Override
    public int seLayoutId () {
        return R.layout.fm_my;
    }

    @Override
    public int setBrVmId () {
        return BR.vm;
    }

    @Override
    public MyFmVm setBrVm () {
        return new ViewModelProvider(this).get(MyFmVm.class);
    }

    @Override
    public void initData () {
        super.initData();
        mReceiver = new ApkDownloadReceiver();
        mActivity.registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    }

    @Override
    public void onDestroy () {
        super.onDestroy();
        mActivity.unregisterReceiver(mReceiver);
    }
}